<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>7-父组件向子组件传值-props属性值类型</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style></style>
  </head>
  <body>
    <div id="app">
      <!-- 2：子组件在挂载的时候，接收父组件的数据， number和boolean是自己的 -->
      <son-ming
        :is-son="fantherInfo"
        :son-str="fatherStr"
        :son-number="12"
        :son-boolean="true"
        :son-array="fatherArray"
        :son-object="fatherObj"
      ></son-ming>
    </div>
    <script>
      Vue.component('sonMing', {
        // 3：必须先以驼峰命名方式接收，自定义属性名，才能在自己的template中使用
        props: [
          'is-son',
          'sonStr',
          'sonNumber',
          'sonBoolean',
          'sonArray',
          'sonObject',
        ],
        data: function () {
          return {
            sonInfo: '我是',
          };
        },
        // 4：可以直接在自己的template中国渲染了
        template: `
        <div>
        <div @click="handle1">{{sonInfo + "==========>" + isSon}}</div>
        <ul>
          <li>{{sonStr}}</li>  
          <li>{{sonNumber}}</li>  
          <li>{{sonBoolean}}</li> 
          <br /> 
          <li v-for="(item, index) in sonArray" :key="index">
            <span>{{item}}</span>  
          </li>  
          <br />
          <li>
            <span>{{sonObject.name}}</span>  
            <br />
            <span>{{sonObject.age}}</span>  
          </li>  
        </ul>
        </div>
        `,
        methods: {
          handle1: function () {
            this.sonInfo = '我是小明,';
          },
        },
      });
      var vm = new Vue({
        el: '#app',
        data: {
          // 1:父组件提供了5大类型的数据
          fantherInfo: '是爸爸的儿子',
          fatherStr: '我是字符串',
          fatherArray: ['apple', 'banana', 'orange'],
          fatherObj: {
            name: '大明爸爸',
            age: 46,
          },
        },
        methods: {},
      });
    </script>
  </body>
</html>
